package com.ruoyi.mdm.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.Arith;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.mdm.domain.*;
import com.ruoyi.mdm.mapper.*;
import com.ruoyi.mdm.service.ISkuSampleService;
import com.ruoyi.mdm.utils.EmailUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ruoyi.mdm.service.impl.SkuMasterServiceImpl.isPositiveNumber;

/**
 * sku主档Service业务层处理
 *
 * @author shiseido
 * @date 2025-03-01
 */
@Service
@Slf4j
public class SkuSampleServiceImpl implements ISkuSampleService {
    @Autowired
    private SkuSampleMapper skuSampleMapper;

    @Autowired
    private SkuSampleMasterSubMapper skuSampleMasterSubMapper;

    @Autowired
    private SkuMasterMapper skuMasterMapper;

    @Autowired
    private SkuMasterSubMapper skuMasterSubMapper;

    @Autowired
    private SkuProductMasterMapper skuProductMasterMapper;

    @Autowired
    private SkuProductMasterSubMapper skuProductMasterSubMapper;

    @Autowired
    private SkuMergeMasterMapper skuMergeMasterMapper;

    @Autowired
    private SkuMergeMasterSubMapper skuMergeMasterSubMapper;

    @Autowired
    private EmailUtils emailUtils;
    @Value("${oauth.responseType}")
    private String responseType;

    @Value("${oauth.clientId}")
    private String clientId;

    @Value("${oauth.redirectUri}")
    private String redirectUri;

    @Value("${oauth.scope}")
    private String scope;

    private static String sendToAdd;
    private static String ccToAdd;
    private static String[] sendTo;
    private static String[] sendCc;

    private static String ownerIdAddSku;

    private static Map<String, String> attachments = new HashMap<>();

    private static String emaiSubject = "【资生堂】_MDM PLUS 小样计算异常！";

    private static HashMap<String,String> InsertLogFalgMap = new HashMap<>();

    private static HashMap<String,BigDecimal> skuOldPriceMap = new HashMap<>();

    private static HashMap<String,SkuMaster> skuNewPriceMap = new HashMap<>();

    private static HashMap<String,String> skuSamplePriceMap = new HashMap<>();

    private static HashMap<String,String> skuSampleSkumMap = new HashMap<>();

    /**
     * 查询sku sample 详情查看
     *
     * @param id sku主档主键
     * @return sku主档
     */
    @Override
    public SkuSampleEntity selectSkuSampleById(Long id, Long infoType) {


        SkuSampleEntity skuSampleEntity = null;
        skuSampleEntity = skuSampleMapper.selectSkuSampleById(id);

        return skuSampleEntity;
    }

    /**
     * 查询sku sample 小样价值
     *
     * @param id sku主档主键
     * @return sku主档
     */
    public SkuSampleEntity selectSkuSampleById(Long id) {


        SkuSampleEntity skuSampleEntity = skuSampleMapper.selectSkuSampleById(id);
        return skuSampleEntity;
    }

    @Override
    public List<SkuSamplePriceEntity> selectSkuSampleValue(SkuSamplePriceEntity entity) {


        return skuSampleMapper.selectSkuSampleValue(entity);
    }

    // 编辑
    @Override
    public int editSkuSampleSub(SkuSampleMasterSub sampleMasterSub) {

        //新建
        SkuSampleMasterSub skuSampleMasterSubOld = skuSampleMasterSubMapper.selectSkuSampleMasterSubBySkuCode(
                sampleMasterSub.getOwnerId(), sampleMasterSub.getSkuCode());
        if (skuSampleMasterSubOld == null) {
            SkuProductMaster retSkuProductMaster = null;
            if (sampleMasterSub.getIsGWP().equalsIgnoreCase("0")) {
                retSkuProductMaster = skuProductMasterMapper.selectSkuProductMasterBySpuCode(sampleMasterSub.getSpuCode());
                if (null == retSkuProductMaster) {
                    log.error("spu code={} no spu name ", sampleMasterSub.getSpuCode());
                    return 0;
                }
            }
            SkuSampleMasterSub skuSampleMasterSub = new SkuSampleMasterSub();
            skuSampleMasterSub.setOwnerId(sampleMasterSub.getOwnerId());
            skuSampleMasterSub.setSkuCode(sampleMasterSub.getSkuCode());
            skuSampleMasterSub.setSkuName(sampleMasterSub.getGoodsName());
            skuSampleMasterSub.setSkuNameEn(sampleMasterSub.getGoodsNameEn());
            skuSampleMasterSub.setSaletype(sampleMasterSub.getSaletype());
            skuSampleMasterSub.setContent(sampleMasterSub.getContent());
            skuSampleMasterSub.setContentUnit(sampleMasterSub.getContentUnit());
            skuSampleMasterSub.setIsGWP(sampleMasterSub.getIsGWP());
            skuSampleMasterSub.setSaletype(sampleMasterSub.getSaletype());
            skuSampleMasterSub.setSpuCode(sampleMasterSub.getSpuCode());
            if (null != retSkuProductMaster) {
                skuSampleMasterSub.setSpuName(retSkuProductMaster.getSpuName());
            }

            skuSampleMasterSub.setCreateBy(sampleMasterSub.getCreateBy());
            skuSampleMasterSub.setCreateTime(DateUtils.getNowDate());
            skuSampleMasterSubMapper.insertSkuSampleMasterSub(skuSampleMasterSub);
        } else {
            SkuSampleMasterSub skuSampleMasterSub = new SkuSampleMasterSub();
            if (sampleMasterSub.getIsGWP().equalsIgnoreCase("1")) {
                skuSampleMasterSub.setContent("");
                skuSampleMasterSub.setContentUnit("");
                skuSampleMasterSub.setSpuCode("");
                skuSampleMasterSub.setSpuName("");
            } else if (sampleMasterSub.getIsGWP().equalsIgnoreCase("0")) {
                skuSampleMasterSub.setContent(sampleMasterSub.getContent());
                skuSampleMasterSub.setContentUnit(sampleMasterSub.getContentUnit());
                skuSampleMasterSub.setSpuCode(sampleMasterSub.getSpuCode());
                SkuProductMaster retSkuProductMaster = null;
                if (sampleMasterSub.getIsGWP().equalsIgnoreCase("0")) {
                    retSkuProductMaster = skuProductMasterMapper.selectSkuProductMasterBySpuCode(sampleMasterSub.getSpuCode());
                    if (null == retSkuProductMaster) {
                        log.error("spu code={} no spu name ", sampleMasterSub.getSpuCode());
                        return 0;
                    }
                    skuSampleMasterSub.setSpuName(retSkuProductMaster.getSpuName());
                }
            }

            skuSampleMasterSub.setOwnerId(sampleMasterSub.getOwnerId());
            skuSampleMasterSub.setSkuCode(sampleMasterSub.getSkuCode());
            skuSampleMasterSub.setSkuName(skuSampleMasterSubOld.getGoodsName());
            skuSampleMasterSub.setSaletype(skuSampleMasterSubOld.getSaletype());
            skuSampleMasterSub.setIsGWP(sampleMasterSub.getIsGWP());
            skuSampleMasterSub.setUpdateBy(skuSampleMasterSubOld.getUpdateBy());
            skuSampleMasterSub.setUpdateTime(DateUtils.getNowDate());
            skuSampleMasterSubMapper.updateSkuSampleMasterSub(skuSampleMasterSub);

        }

        if (null != sampleMasterSub &&
                null != skuSampleMasterSubOld
        ) {
            compareSkuSample(sampleMasterSub, skuSampleMasterSubOld);
        }

        return 1;
    }

    private void compareSkuSample(SkuSampleMasterSub sampleEntity, SkuSampleMasterSub skuSampleMasterSubOld) {
        log.debug("enter compareSkuSample,new data={},old data={}", sampleEntity.toString(), skuSampleMasterSubOld.toString());

        if (!sampleEntity.getIsGWP().equalsIgnoreCase(skuSampleMasterSubOld.getIsGWP())) {
            String newGWP = "";
            if (sampleEntity.getIsGWP().equalsIgnoreCase("0")) {
                newGWP = "否";
            } else {
                newGWP = "是";
            }
            String oldGWP = "";
            if (skuSampleMasterSubOld.getIsGWP().equalsIgnoreCase("0")) {
                oldGWP = "否";
            } else {
                oldGWP = "是";
            }

            //追溯历史
            SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
            skuSampleUpdateLog.setOwnerId(sampleEntity.getOwnerId());
            skuSampleUpdateLog.setSkuCode(sampleEntity.getSkuCode());
            skuSampleUpdateLog.setSkuName(sampleEntity.getGoodsName());
            skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.UPDATE_GWP.getDesc()));
            skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SKU_SAMPLE.getDesc()));
            skuSampleUpdateLog.setOldValue(oldGWP);
            skuSampleUpdateLog.setNewValue(newGWP);
            skuSampleUpdateLog.setUpdateBy(sampleEntity.getCreateBy());
            skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
            skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);

//            SkuSampleUpdateLog updateLog = new SkuSampleUpdateLog();
//            updateLog.setOwnerId(sampleEntity.getOwnerId());
//            updateLog.setSkuCode(sampleEntity.getSkuCode());
//            updateLog.setMtype(SkuMasterConstants.SKU_SAMPLE_M_TYPE.UPDATE_GWP.getDesc());
//            List<SkuSampleUpdateLog> retList = skuSampleMapper.getSkuSampleUpdateLog(updateLog);
//            if (null == retList || retList.isEmpty()) {
//                SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
//                skuSampleUpdateLog.setOwnerId(sampleEntity.getOwnerId());
//                skuSampleUpdateLog.setSkuCode(sampleEntity.getSkuCode());
//                skuSampleUpdateLog.setSkuName(sampleEntity.getGoodsName());
//                skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.UPDATE_GWP.getDesc()));
//                skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SKU_SAMPLE.getDesc()));
//                skuSampleUpdateLog.setOldValue(oldGWP);
//                skuSampleUpdateLog.setNewValue(newGWP);
//                skuSampleUpdateLog.setUpdateBy(sampleEntity.getCreateBy());
//                skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
//                skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);
//            } else {
//                SkuSampleUpdateLog tmpLog = retList.get(0);
//                tmpLog.setOldValue(oldGWP);
//                tmpLog.setNewValue(newGWP);
//                tmpLog.setUpdateTime(DateUtils.getNowDate());
//                skuSampleMapper.updateSkuSampleUpdateLog(tmpLog);
//            }
        }

        //容量比对
//        if (StringUtils.isNotEmpty(sampleEntity.getContent()) && StringUtils.isNotEmpty(skuSampleMasterSubOld.getContent())) {
        if (!sampleEntity.getContent().equalsIgnoreCase(skuSampleMasterSubOld.getContent())) {
            //追溯历史
            SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
            skuSampleUpdateLog.setOwnerId(sampleEntity.getOwnerId());
            skuSampleUpdateLog.setSkuCode(sampleEntity.getSkuCode());
            skuSampleUpdateLog.setSkuName(sampleEntity.getGoodsName());
            skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_CONTENT.getDesc()));
            skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SKU_SAMPLE.getDesc()));
            skuSampleUpdateLog.setOldValue(skuSampleMasterSubOld.getContent());
            skuSampleUpdateLog.setNewValue(sampleEntity.getContent());
            skuSampleUpdateLog.setUpdateBy(sampleEntity.getCreateBy());
            skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
            skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);

            //            SkuSampleUpdateLog updateLog = new SkuSampleUpdateLog();
//            updateLog.setOwnerId(sampleEntity.getOwnerId());
//            updateLog.setSkuCode(sampleEntity.getSkuCode());
//            updateLog.setMtype(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_CONTENT.getDesc());
//            List<SkuSampleUpdateLog> retList = skuSampleMapper.getSkuSampleUpdateLog(updateLog);
//            if (null == retList || retList.isEmpty()) {
//                SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
//                skuSampleUpdateLog.setOwnerId(sampleEntity.getOwnerId());
//                skuSampleUpdateLog.setSkuCode(sampleEntity.getSkuCode());
//                skuSampleUpdateLog.setSkuName(sampleEntity.getGoodsName());
//                skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_CONTENT.getDesc()));
//                skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SKU_SAMPLE.getDesc()));
//                skuSampleUpdateLog.setOldValue("");
//                skuSampleUpdateLog.setNewValue(sampleEntity.getContent());
//                skuSampleUpdateLog.setUpdateBy(sampleEntity.getCreateBy());
//                skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
//                skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);
//            } else {
//                SkuSampleUpdateLog tmpLog = retList.get(0);
//                tmpLog.setOldValue(skuSampleMasterSubOld.getContent());
//                tmpLog.setNewValue(sampleEntity.getContent());
//                tmpLog.setUpdateTime(DateUtils.getNowDate());
//                skuSampleMapper.updateSkuSampleUpdateLog(tmpLog);
//            }
        }
//        }

        //容量单位比对
//        if (StringUtils.isNotEmpty(sampleEntity.getContentUnit()) && StringUtils.isNotEmpty(skuSampleMasterSubOld.getContentUnit())) {
        if (!sampleEntity.getContentUnit().equalsIgnoreCase(skuSampleMasterSubOld.getContentUnit())) {
            //追溯历史
            SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
            skuSampleUpdateLog.setOwnerId(sampleEntity.getOwnerId());
            skuSampleUpdateLog.setSkuCode(sampleEntity.getSkuCode());
            skuSampleUpdateLog.setSkuName(sampleEntity.getGoodsName());
            skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_CONTENTUNIT.getDesc()));
            skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SKU_SAMPLE.getDesc()));
            skuSampleUpdateLog.setOldValue(skuSampleMasterSubOld.getContentUnit());
            skuSampleUpdateLog.setNewValue(sampleEntity.getContentUnit());
            skuSampleUpdateLog.setUpdateBy(sampleEntity.getCreateBy());
            skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
            skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);

//            SkuSampleUpdateLog updateLog = new SkuSampleUpdateLog();
//            updateLog.setOwnerId(sampleEntity.getOwnerId());
//            updateLog.setSkuCode(sampleEntity.getSkuCode());
//            updateLog.setMtype(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_CONTENTUNIT.getDesc());

//            List<SkuSampleUpdateLog> retList = skuSampleMapper.getSkuSampleUpdateLog(updateLog);
//            if (null == retList || retList.isEmpty()) {
//                SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
//                skuSampleUpdateLog.setOwnerId(sampleEntity.getOwnerId());
//                skuSampleUpdateLog.setSkuCode(sampleEntity.getSkuCode());
//                skuSampleUpdateLog.setSkuName(sampleEntity.getGoodsName());
//                skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_CONTENTUNIT.getDesc()));
//                skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SKU_SAMPLE.getDesc()));
//                skuSampleUpdateLog.setOldValue(skuSampleMasterSubOld.getContentUnit());
//                skuSampleUpdateLog.setNewValue(sampleEntity.getContentUnit());
//                skuSampleUpdateLog.setUpdateBy(sampleEntity.getCreateBy());
//                skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
//                skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);
//            } else {
//                SkuSampleUpdateLog tmpLog = retList.get(0);
//                tmpLog.setOldValue(skuSampleMasterSubOld.getContentUnit());
//                tmpLog.setNewValue(sampleEntity.getContentUnit());
//                tmpLog.setUpdateTime(DateUtils.getNowDate());
//                skuSampleMapper.updateSkuSampleUpdateLog(tmpLog);
//            }
        }
//        }

        //spu比对
//        if (StringUtils.isNotEmpty(sampleEntity.getSpuCode()) && StringUtils.isNotEmpty(skuSampleMasterSubOld.getSpuCode())) {
        if (!sampleEntity.getSpuCode().equalsIgnoreCase(skuSampleMasterSubOld.getSpuCode())) {
            //追溯历史
            SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
            skuSampleUpdateLog.setOwnerId(sampleEntity.getOwnerId());
            skuSampleUpdateLog.setSkuCode(sampleEntity.getSkuCode());
            skuSampleUpdateLog.setSkuName(sampleEntity.getGoodsName());
            skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_SPU.getDesc()));
            skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SKU_SAMPLE.getDesc()));
            skuSampleUpdateLog.setOldValue(skuSampleMasterSubOld.getSpuCode());
            skuSampleUpdateLog.setNewValue(sampleEntity.getSpuCode());
            skuSampleUpdateLog.setUpdateBy(sampleEntity.getCreateBy());
            skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
            skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);

//            SkuSampleUpdateLog updateLog = new SkuSampleUpdateLog();
//            updateLog.setOwnerId(sampleEntity.getOwnerId());
//            updateLog.setSkuCode(sampleEntity.getSkuCode());
//            updateLog.setMtype(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_SPU.getDesc());
//            List<SkuSampleUpdateLog> retList = skuSampleMapper.getSkuSampleUpdateLog(updateLog);
//            if (null == retList || retList.isEmpty()) {
//                SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
//                skuSampleUpdateLog.setOwnerId(sampleEntity.getOwnerId());
//                skuSampleUpdateLog.setSkuCode(sampleEntity.getSkuCode());
//                skuSampleUpdateLog.setSkuName(sampleEntity.getGoodsName());
//                skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_SPU.getDesc()));
//                skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SKU_SAMPLE.getDesc()));
//                skuSampleUpdateLog.setOldValue(skuSampleMasterSubOld.getSpuCode());
//                skuSampleUpdateLog.setNewValue(sampleEntity.getSpuCode());
//                skuSampleUpdateLog.setUpdateBy(sampleEntity.getCreateBy());
//                skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
//                skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);
//            } else {
//                SkuSampleUpdateLog tmpLog = retList.get(0);
//                tmpLog.setOldValue(skuSampleMasterSubOld.getSpuCode());
//                tmpLog.setNewValue(sampleEntity.getSpuCode());
//                tmpLog.setUpdateTime(DateUtils.getNowDate());
//                skuSampleMapper.updateSkuSampleUpdateLog(tmpLog);
//            }
        }
//        }

    }


    /**
     * 查询sku主档列表
     *
     * @param SkuSampleEntity sku主档
     * @return sku主档集合
     */
    @Override
    public List<SkuSampleEntity> selectSkuSampleList(SkuSampleEntity SkuSampleEntity) {
        return skuSampleMapper.selectSkuSampleList(SkuSampleEntity);
    }

    @Override
    public SkuSamplePriceEntity getSkuMaxMinPrice(SkuSamplePriceEntity SkuSampleEntity) {
        return skuSampleMapper.getSkuMaxMinPrice(SkuSampleEntity);
    }

    @Override
    public List<SkuSampleEntity> getOneSku(SkuSampleEntity SkuSampleEntity) {
        return skuSampleMapper.getOneSku(SkuSampleEntity);
    }

    @Override
    public int insertSkuSampleSub(SkuSampleMasterSub sampleMasterSub) {
        return skuSampleMasterSubMapper.insertSkuSampleMasterSub(sampleMasterSub);
    }

    /**
     * 导入产品
     *
     * @param skuSampleSubImportList 推荐渠道数据列表
     * @param operName               操作用户
     * @return 结果
     */
    @Override
    @Transactional
    public List<Map> importSkuSampleSub(List<SkuSampleImport> skuSampleSubImportList,
                                        String operName) {
        List<Map> messageList = new ArrayList<>();
        Map<String, String> messageMap = new HashMap<>();

        List<SkuSampleMasterSub> skuSampleList = new ArrayList<>();

        // 小样容量和关联SPU
        int index = 1;
        String sheetName1 = "小样容量和关联SPU";
        for (SkuSampleImport anImport : skuSampleSubImportList) {
            index = index + 1;
            // 产品编码必填
            if (StringUtils.isEmpty(anImport.getGoodsCode())) {
                messageMap = new HashMap<>();
                messageMap.put("sheetName", sheetName1);
                messageMap.put("index", String.valueOf(index));
                messageMap.put("message", "产品编码必填！");
                messageList.add(messageMap);
                continue;
            }

            // 品牌必填
            if (StringUtils.isEmpty(anImport.getBrandName())) {
                messageMap = new HashMap<>();
                messageMap.put("sheetName", sheetName1);
                messageMap.put("index", String.valueOf(index));
                messageMap.put("message", "品牌必填！");
                messageList.add(messageMap);
                continue;
            }

            String ownerId = DictUtils.getDictValue("goods_brand", anImport.getBrandName());
            if (StringUtils.isEmpty(ownerId)) {
                messageMap = new HashMap<>();
                messageMap.put("sheetName", sheetName1);
                messageMap.put("index", String.valueOf(index));
                messageMap.put("message", "品牌:【" + anImport.getBrandName() + "】在数据字典中不存在！");
                messageList.add(messageMap);
                continue;
            }

            SkuSampleEntity skuMasterTmp = new SkuSampleEntity();
            skuMasterTmp.setGoodsCode(anImport.getGoodsCode());
            skuMasterTmp.setOwnerId(ownerId);
            List<SkuSampleEntity> skuMasterList = skuSampleMapper.selectSkuSampleList(skuMasterTmp);
            if (StringUtils.isEmpty(skuMasterList)) {
                messageMap = new HashMap<>();
                messageMap.put("sheetName", sheetName1);
                messageMap.put("index", String.valueOf(index));
                messageMap.put("message", "品牌:【" + anImport.getBrandName()
                        + "】产品编码:【" + anImport.getGoodsCode() + "】不存在！");
                messageList.add(messageMap);
                continue;
            }
            SkuSampleEntity skuMaster = skuMasterList.get(0);


            if (StringUtils.isEmpty(anImport.getIsGWP())) {
                messageMap = new HashMap<>();
                messageMap.put("sheetName", sheetName1);
                messageMap.put("index", String.valueOf(index));
                messageMap.put("message", "是否是GWP(*) 设置异常！");
                messageList.add(messageMap);
                continue;
            }
            SkuProductMaster skuProductMaster = new SkuProductMaster();
            //校验容量，spu name
            if (anImport.getIsGWP().equalsIgnoreCase("否")) {
                // 容量校验
                if (StringUtils.isEmpty(anImport.getSpuName())) {
                    messageMap = new HashMap<>();
                    messageMap.put("sheetName", sheetName1);
                    messageMap.put("index", String.valueOf(index));
                    messageMap.put("message", "spu 名称设置异常！");
                    messageList.add(messageMap);
                    continue;
                }

                // check spu 中文名称
                skuProductMaster.setOwnerId(ownerId);
                skuProductMaster.setSpuName(anImport.getSpuName());
//                skuProductMaster.setSearchSpuName(anImport.getSpuName());
                List<SkuProductMaster> skuProductMasterList = skuProductMasterMapper.selectSkuProductMasterList(skuProductMaster);
                if (StringUtils.isEmpty(skuProductMasterList)) {
                    messageMap = new HashMap<>();
                    messageMap.put("sheetName", sheetName1);
                    messageMap.put("index", String.valueOf(index));
                    messageMap.put("message", "品牌:【" + anImport.getBrandName()
                            + "】SPU中文名称:【" + anImport.getSpuName() + "】不存在！");
                    messageList.add(messageMap);
                    continue;
                }
                skuProductMaster = skuProductMasterList.get(0);
                // 容量校验
                if (StringUtils.isEmpty(anImport.getContent()) || !isPositiveNumber(anImport.getContent())) {
                    messageMap = new HashMap<>();
                    messageMap.put("sheetName", sheetName1);
                    messageMap.put("index", String.valueOf(index));
                    messageMap.put("message", "容量=" + anImport.getContent() + "设置异常！");
                    messageList.add(messageMap);
                    continue;
                }

                // 容量单位
                if (StringUtils.isEmpty(anImport.getContentUnit()) || StringUtils.isEmpty(anImport.getContentUnit())) {
                    messageMap = new HashMap<>();
                    messageMap.put("sheetName", sheetName1);
                    messageMap.put("index", String.valueOf(index));
                    messageMap.put("message", "容量单位必填！");
                    messageList.add(messageMap);
                    continue;
                }

                //容量单位 校验
                if (!anImport.getContentUnit().equalsIgnoreCase("ml") &&
                        !anImport.getContentUnit().equalsIgnoreCase("g") &&
                        !anImport.getContentUnit().equalsIgnoreCase("pc")
                ) {
                    messageMap = new HashMap<>();
                    messageMap.put("sheetName", sheetName1);
                    messageMap.put("index", String.valueOf(index));
                    messageMap.put("message", "容量单位错误！ 正确的是：ml/g/pc");
                    messageList.add(messageMap);
                    continue;
                }
            }

            SkuSampleMasterSub skuSampleMasterSub = new SkuSampleMasterSub();
            skuSampleMasterSub.setOwnerId(ownerId);
            skuSampleMasterSub.setSkuCode(skuMaster.getGoodsCode());
            skuSampleMasterSub.setSkuName(skuMaster.getGoodsName());
            skuSampleMasterSub.setSkuNameEn(skuMaster.getGoodsNameEn());

            skuSampleMasterSub.setIsGWP(anImport.getIsGWP());
            if (anImport.getIsGWP().equalsIgnoreCase("否")) {
                skuSampleMasterSub.setContent(anImport.getContent());
                skuSampleMasterSub.setContentUnit(anImport.getContentUnit());
                skuSampleMasterSub.setSpuCode(skuProductMaster.getSpuCode());
                skuSampleMasterSub.setSpuName(skuProductMaster.getSpuName());
            }
            skuSampleList.add(skuSampleMasterSub);
        }

        //写日志
        if (messageList != null && messageList.size() > 0) {
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                String json = objectMapper.writeValueAsString(messageList);
                throw new ServiceException(json);
            } catch (JsonProcessingException e) {
            }
        }

        //小样容量和关联SPU
        insertSkuSampleSubList(skuSampleList, operName);
        return null;
    }

    /**
     * 导入 小样容量和关联SPU
     */
    private void insertSkuSampleSubList(List<SkuSampleMasterSub> skuSampleImportList, String operName) {
        // 更新  sku_sample_master_sub
        for (SkuSampleMasterSub sampleMasterSub : skuSampleImportList) {
//            log.info("Insert into sku_sample_master_sub, data={}", sampleMasterSub.toString());
            SkuSampleMasterSub skuSampleMasterSub = new SkuSampleMasterSub();
            skuSampleMasterSub.setOwnerId(sampleMasterSub.getOwnerId());
            skuSampleMasterSub.setSkuCode(sampleMasterSub.getSkuCode());

            SkuSampleMasterSub skuSampleMasterSubRet = skuSampleMasterSubMapper.selectSkuSampleMasterSubBySkuCode(sampleMasterSub.getOwnerId(), String.valueOf(sampleMasterSub.getSkuCode()));

            // 如果存在删除，再新增关联
            if (skuSampleMasterSubRet != null) {
                skuSampleMasterSubMapper.deleteSkuSampleMasterSubById(skuSampleMasterSubRet.getId());
            }
            SkuSampleMasterSub skuSampleMasterSub1 = new SkuSampleMasterSub();
            skuSampleMasterSub1.setOwnerId(sampleMasterSub.getOwnerId());
            skuSampleMasterSub1.setSkuCode(sampleMasterSub.getSkuCode());
            skuSampleMasterSub1.setSkuName(sampleMasterSub.getSkuName());
            skuSampleMasterSub1.setSkuNameEn(sampleMasterSub.getSkuNameEn());
            skuSampleMasterSub1.setSaletype(sampleMasterSub.getSaletype());
            skuSampleMasterSub1.setContent(sampleMasterSub.getContent());
            skuSampleMasterSub1.setContentUnit(sampleMasterSub.getContentUnit());
            if (sampleMasterSub.getIsGWP().equalsIgnoreCase("否")) {
                skuSampleMasterSub1.setIsGWP("0");
            } else if (sampleMasterSub.getIsGWP().equalsIgnoreCase("是")) {
                skuSampleMasterSub1.setIsGWP("1");
            } else {
                log.error("isGWP error.value={}", sampleMasterSub.getIsGWP());
            }

            skuSampleMasterSub1.setSpuCode(sampleMasterSub.getSpuCode());
            skuSampleMasterSub1.setSpuName(sampleMasterSub.getSpuName());
            skuSampleMasterSub1.setCreateBy(operName);
//            skuSampleMasterSub1.setUpdateBy(operName);
            skuSampleMasterSub1.setCreateTime(DateUtils.getNowDate());
//            skuSampleMasterSub1.setUpdateTime(DateUtils.getNowDate());
            skuSampleMasterSubMapper.insertSkuSampleMasterSub(skuSampleMasterSub1);

        }
    }


    @Override
    public int skuSampleCalPrice(String ownerId, String operName) {
        log.info("enter skuSampleCalPrice,load cache");
        StringBuffer emailBodyError = new StringBuffer("Dears,<br/>\n" +
                "今天小样价格计算失败，请及时进行检查。 <br/>\n");
        try {
            InsertLogFalgMap.clear();
            skuOldPriceMap.clear();
            skuNewPriceMap.clear();
            skuSamplePriceMap.clear();
            skuSampleSkumMap.clear();
            //truncate tables
            log.info("truncate tables ....... ");
            skuSampleMapper.truncateTablesSkuData1();
//        skuSampleMapper.truncateTablesSkuData2();
            skuSampleMapper.truncateTablesSkuData3();
            skuSampleMapper.truncateTablesSkuData4();
            skuSampleMapper.truncateTablesSkuData5();
            skuSampleMapper.truncateTablesSkuData6();
            skuSampleMapper.truncateTablesSkuData7();
            List<SkuEmailAddressEntity> skuEmailAddressList = skuSampleMapper.getSkuEmailAddressList();
            if (null == skuEmailAddressList || skuEmailAddressList.isEmpty()) {
                log.error("email address is null. please check table sku_email_address");
                return -1;
            } else {
                SkuEmailAddressEntity addressEntity = skuEmailAddressList.get(0);
                sendToAdd = addressEntity.getSend_to();
                ccToAdd = addressEntity.getCc_to();
                ownerIdAddSku = addressEntity.getRemark();

                //send email
                if (StringUtils.isEmpty(sendToAdd)) {
                    log.error("send emaill address is null");
                    return -1;
                }
                sendTo = sendToAdd.split(",");

                if (!StringUtils.isEmpty(ccToAdd)) {
                    sendCc = ccToAdd.split(",");
                }
            }


            // 遍历 sku_sample_master_sub
            SkuSampleMasterSub tmpParam = new SkuSampleMasterSub();
            tmpParam.setOwnerId(ownerId);
            List<SkuSampleMasterSub> skuSampleMasterSubList = skuSampleMasterSubMapper.selectSkuSampleMasterSubList(tmpParam);
            if (skuSampleMasterSubList.isEmpty()) {
                log.error("配置表为空，没有需要计算的配置信息，请确认！！");
                return -1;
            }
            // 加载缓存
            if (SkuMasterConstants.SPU_CODE_NAME_MAP.isEmpty() ||
                    SkuMasterConstants.SKUM_CODE_NAME_MAP.isEmpty()
            ) {
                SkuProductMaster skuProductMaste = new SkuProductMaster();
                List<SkuProductMaster> skuProductMasterList = skuProductMasterMapper.selectSkuProductMasterList(skuProductMaste);
                for (SkuProductMaster productMaster : skuProductMasterList) {
                    SkuMasterConstants.SPU_CODE_NAME_MAP.put(productMaster.getSpuCode(), productMaster.getSpuName());
                }

                SkuMergeMaster skuMergeMaster = new SkuMergeMaster();
                List<SkuMergeMaster> skuMergeMasterList = skuMergeMasterMapper.selectSkuMergeMasterList(skuMergeMaster);
                for (SkuMergeMaster skuMergeMaster1 : skuMergeMasterList) {
                    SkuMasterConstants.SKUM_CODE_NAME_MAP.put(skuMergeMaster1.getSkumCode(), skuMergeMaster1.getSkumName());
                }
            }
            for (SkuSampleMasterSub sampleMasterSub : skuSampleMasterSubList) {
                log.debug("sample sku deal value={}", sampleMasterSub.toString());
                if (StringUtils.isEmpty(sampleMasterSub.getIsGWP()) ||
                        sampleMasterSub.getIsGWP().equalsIgnoreCase("1")) {
                    log.info("sku no need to calculate price! sku={}", sampleMasterSub.toString());

                    continue;
                }
                if (StringUtils.isEmpty(sampleMasterSub.getOwnerId()) ||
                        StringUtils.isEmpty(sampleMasterSub.getSpuCode())) {
                    log.error("please check! ownerid or spu code is null! sku={}", sampleMasterSub.toString());
                    // 写入异常表
                    SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
                    skuSamplePriceCalErrorEntity.setOwnerId(sampleMasterSub.getOwnerId());
                    skuSamplePriceCalErrorEntity.setGoodsCode(sampleMasterSub.getSkuCode());
                    skuSamplePriceCalErrorEntity.setGoodsName(sampleMasterSub.getSkuName());
                    skuSamplePriceCalErrorEntity.setGoodsNameEn(sampleMasterSub.getSkuNameEn());
//                skuSamplePriceCalErrorEntity.setTimes();
                    skuSamplePriceCalErrorEntity.setSaletype(sampleMasterSub.getSaletype());
                    skuSamplePriceCalErrorEntity.setReason("sku =" + sampleMasterSub.getSkuCode() + " 的spu code不存在");
                    skuSamplePriceCalErrorEntity.setCreateBy(operName);
                    skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());
                    skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);

                    continue;
                }
                // 根据小样绑定的spu code 找到所有的 skum
                SkuProductMasterSub skuProductMasterSubTmp = new SkuProductMasterSub();
                skuProductMasterSubTmp.setOwnerId(sampleMasterSub.getOwnerId());
                skuProductMasterSubTmp.setSpuCode(sampleMasterSub.getSpuCode());
                List<SkuProductMasterSub> skuProductMasterSubList = skuProductMasterSubMapper.selectSkuProductMasterSubList(skuProductMasterSubTmp);
                if (skuProductMasterSubList.isEmpty()) {
                    // 写入异常表
                    SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
                    skuSamplePriceCalErrorEntity.setOwnerId(sampleMasterSub.getOwnerId());
                    skuSamplePriceCalErrorEntity.setGoodsCode(sampleMasterSub.getSkuCode());
                    skuSamplePriceCalErrorEntity.setGoodsName(sampleMasterSub.getSkuName());
                    skuSamplePriceCalErrorEntity.setGoodsNameEn(sampleMasterSub.getSkuNameEn());
//                skuSamplePriceCalErrorEntity.setTimes();
                    skuSamplePriceCalErrorEntity.setSaletype(sampleMasterSub.getSaletype());
                    skuSamplePriceCalErrorEntity.setReason("spu=" + sampleMasterSub.getSpuCode() + " 没有关联的skum");
                    skuSamplePriceCalErrorEntity.setCreateBy(operName);
                    skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());

                    skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);
                    log.error("spucode={} 没有关联的skum", sampleMasterSub.getSpuCode());

                    continue;
                }
                // get all sku_code
                for (SkuProductMasterSub skuProductMasterSub : skuProductMasterSubList) {
//                    log.debug("spu deal value={}", skuProductMasterSub.toString());
                    if (skuProductMasterSub.getOwnerId() == null ||
                            skuProductMasterSub.getSkumCode() == null) {
                        log.error("please check! skum code is null! spu={}", skuProductMasterSub.toString());
                        // 写入异常表
                        SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
                        skuSamplePriceCalErrorEntity.setOwnerId(sampleMasterSub.getOwnerId());
                        skuSamplePriceCalErrorEntity.setGoodsCode(sampleMasterSub.getSkuCode());
                        skuSamplePriceCalErrorEntity.setGoodsName(sampleMasterSub.getSkuName());
                        skuSamplePriceCalErrorEntity.setGoodsNameEn(sampleMasterSub.getSkuNameEn());
                        skuSamplePriceCalErrorEntity.setSaletype(sampleMasterSub.getSaletype());
                        skuSamplePriceCalErrorEntity.setReason("spu " + skuProductMasterSub.getSpuCode() + " 关联的skum code 是空值");
                        skuSamplePriceCalErrorEntity.setCreateBy(operName);
                        skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());
                        skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);
                        continue;
                    }

                    //根据skum code找到信息
                    SkuMergeMaster skuMergeMaster = new SkuMergeMaster();
                    skuMergeMaster.setSkumCode(skuProductMasterSub.getSkumCode());
                    List<SkuMergeMaster> skuMergeMasterList = skuMergeMasterMapper.selectSkuMergeMasterList(skuMergeMaster);
                    if (skuMergeMasterList.isEmpty()) {
                        // 写入异常表
                        SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
                        skuSamplePriceCalErrorEntity.setOwnerId(skuProductMasterSub.getOwnerId());
                        skuSamplePriceCalErrorEntity.setGoodsCode(sampleMasterSub.getSkuCode());
                        skuSamplePriceCalErrorEntity.setGoodsName(sampleMasterSub.getSkuName());
                        skuSamplePriceCalErrorEntity.setGoodsNameEn(sampleMasterSub.getSkuNameEn());
                        skuSamplePriceCalErrorEntity.setSaletype(sampleMasterSub.getSaletype());
                        skuSamplePriceCalErrorEntity.setReason("spu=" + sampleMasterSub.getSpuCode() + " 没有关联的skum");
                        skuSamplePriceCalErrorEntity.setCreateBy(operName);
                        skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());

                        skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);
                        continue;
                    }

                    // get al skum
                    for (SkuMergeMaster mergeMaster : skuMergeMasterList) {
                        log.debug("skum deal value={}", mergeMaster.toString());
                        if (StringUtils.isEmpty(mergeMaster.getSkumNetWeight())) {
                            // 写入异常表
                            SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
                            skuSamplePriceCalErrorEntity.setOwnerId(sampleMasterSub.getOwnerId());
                            skuSamplePriceCalErrorEntity.setGoodsCode(sampleMasterSub.getSkuCode());
                            skuSamplePriceCalErrorEntity.setGoodsName(sampleMasterSub.getSkuName());
                            skuSamplePriceCalErrorEntity.setGoodsNameEn(sampleMasterSub.getSkuNameEn());
                            skuSamplePriceCalErrorEntity.setSaletype(sampleMasterSub.getSaletype());
                            skuSamplePriceCalErrorEntity.setReason("skum " + mergeMaster.getSkumCode() + " 容量为空");
                            skuSamplePriceCalErrorEntity.setCreateBy(operName);
                            skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());
                            skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);

                            continue;
                        }
                        if (null == mergeMaster.getSkumSalePrice()) {
                            // 写入异常表
                            SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
                            skuSamplePriceCalErrorEntity.setOwnerId(sampleMasterSub.getOwnerId());
                            skuSamplePriceCalErrorEntity.setGoodsCode(sampleMasterSub.getSkuCode());
                            skuSamplePriceCalErrorEntity.setGoodsName(sampleMasterSub.getSkuName());
                            skuSamplePriceCalErrorEntity.setGoodsNameEn(sampleMasterSub.getSkuNameEn());
                            skuSamplePriceCalErrorEntity.setSaletype(sampleMasterSub.getSaletype());
                            skuSamplePriceCalErrorEntity.setReason("skum " + mergeMaster.getSkumCode() + "  价格为空");
                            skuSamplePriceCalErrorEntity.setCreateBy(operName);
                            skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());
                            skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);

                            continue;
                        }

                        // 计算小样的价格
                        double epsilon = 1e-9;
                        if (Math.abs(Double.valueOf(mergeMaster.getSkumSalePrice().toString())) < epsilon) {
                            log.error("skum price =0 data={}", mergeMaster.toString());
                            // 写入异常表
                            SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
                            skuSamplePriceCalErrorEntity.setOwnerId(sampleMasterSub.getOwnerId());
                            skuSamplePriceCalErrorEntity.setGoodsCode(sampleMasterSub.getSkuCode());
                            skuSamplePriceCalErrorEntity.setGoodsName(sampleMasterSub.getSkuName());
                            skuSamplePriceCalErrorEntity.setGoodsNameEn(sampleMasterSub.getSkuNameEn());
                            skuSamplePriceCalErrorEntity.setSaletype(sampleMasterSub.getSaletype());
                            skuSamplePriceCalErrorEntity.setReason("skum " + mergeMaster.getSkumCode() + " 价格是0,请确认！");
                            skuSamplePriceCalErrorEntity.setCreateBy(operName);
                            skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());
                            skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);

                            continue;
                        }
                        if (Math.abs(Double.valueOf(mergeMaster.getSkumNetWeight())) < epsilon) {
                            log.error("Skum Net Weight=0 data={}", mergeMaster.toString());
                            // 写入异常表
                            SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
                            skuSamplePriceCalErrorEntity.setOwnerId(sampleMasterSub.getOwnerId());
                            skuSamplePriceCalErrorEntity.setGoodsCode(sampleMasterSub.getSkuCode());
                            skuSamplePriceCalErrorEntity.setGoodsName(sampleMasterSub.getSkuName());
                            skuSamplePriceCalErrorEntity.setGoodsNameEn(sampleMasterSub.getSkuNameEn());
                            skuSamplePriceCalErrorEntity.setSaletype(sampleMasterSub.getSaletype());
                            skuSamplePriceCalErrorEntity.setReason("skum " + mergeMaster.getSkumCode() + " 容量是0,请确认！");
                            skuSamplePriceCalErrorEntity.setCreateBy(operName);
                            skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());
                            skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);

                            continue;
                        }
                        if (StringUtils.isEmpty(sampleMasterSub.getContent()) ||
                                Math.abs(Double.valueOf(sampleMasterSub.getContent())) < epsilon) {
                            log.error("Sku sample content=0 data={}", sampleMasterSub.toString());
                            // 写入异常表
                            SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
                            skuSamplePriceCalErrorEntity.setOwnerId(sampleMasterSub.getOwnerId());
                            skuSamplePriceCalErrorEntity.setGoodsCode(sampleMasterSub.getSkuCode());
                            skuSamplePriceCalErrorEntity.setGoodsName(sampleMasterSub.getSkuName());
                            skuSamplePriceCalErrorEntity.setGoodsNameEn(sampleMasterSub.getSkuNameEn());
                            skuSamplePriceCalErrorEntity.setSaletype(sampleMasterSub.getSaletype());
                            skuSamplePriceCalErrorEntity.setReason("sku sample " + sampleMasterSub.getSkuCode() + " 容量是0,请确认！");
                            skuSamplePriceCalErrorEntity.setCreateBy(operName);
                            skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());
                            skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);

                            continue;
                        }
                        ;
                        Double skuDivPrice = Arith.div(Double.valueOf(mergeMaster.getSkumSalePrice().doubleValue()), Double.valueOf(mergeMaster.getSkumNetWeight()), 4);
                        Double newSamplePrice = Arith.round(Arith.mul(skuDivPrice, Double.valueOf(sampleMasterSub.getContent())), 2);
                        log.debug("skusaleprice={},content={}, skuDivPrice={}, sampleContent={}, newSamplePrice={}", mergeMaster.getSkumSalePrice(), mergeMaster.getSkumNetWeight(), skuDivPrice, sampleMasterSub.getContent(), newSamplePrice);

//                        //get 正装的价格
//                        SkuSamplePriceEntity priceBySkuCode = skuSampleMapper.getSkuSamplePriceBySkuCode(sampleMasterSub.getOwnerId(), sampleMasterSub.getSkuCode(), mergeMaster.getSkumCode());
//                        if (priceBySkuCode == null) {
//
//                        }
                        SkuSamplePriceEntity priceBySkuCode = null;
                        if (null == skuSamplePriceMap.get("SKU_SAMPLE_PRICE"+sampleMasterSub.getOwnerId()+sampleMasterSub.getSkuCode()+mergeMaster.getSkumCode())){
                            skuSamplePriceMap.put("SKU_SAMPLE_PRICE"+sampleMasterSub.getOwnerId()+sampleMasterSub.getSkuCode()+mergeMaster.getSkumCode(),"1");
                            // 计算结果写入表
                            SkuSamplePriceEntity skuSamplePriceEntity = new SkuSamplePriceEntity();
                            skuSamplePriceEntity.setOwnerId(sampleMasterSub.getOwnerId());
                            skuSamplePriceEntity.setSpuCode(sampleMasterSub.getSpuCode());
                            skuSamplePriceEntity.setSpuName(sampleMasterSub.getSpuName());
                            skuSamplePriceEntity.setSampleSkuCode(sampleMasterSub.getSkuCode());
                            skuSamplePriceEntity.setSampleSkuName(sampleMasterSub.getSkuName());
                            skuSamplePriceEntity.setSkumCode(mergeMaster.getSkumCode());
                            skuSamplePriceEntity.setSkumName(SkuMasterConstants.SKUM_CODE_NAME_MAP.get(mergeMaster.getSkumCode()));
                            skuSamplePriceEntity.setSaletype(sampleMasterSub.getSaletype());
                            skuSamplePriceEntity.setSalePrice(mergeMaster.getSkumSalePrice());
                            skuSamplePriceEntity.setContent(mergeMaster.getSkumNetWeight());
                            skuSamplePriceEntity.setSamplePrice(BigDecimal.valueOf(newSamplePrice));
                            skuSamplePriceEntity.setSampleContent(sampleMasterSub.getContent());
                            skuSamplePriceEntity.setCreateBy(operName);
                            skuSamplePriceEntity.setCreateTime(DateUtils.getNowDate());

                            log.debug("insert into sku_sample_price, value={}", skuSamplePriceEntity.toString());
                            skuSampleMapper.insertSkuSamplePriceCalLog(skuSamplePriceEntity);
                        }
                        else {
                            //小样价值变动
                            BigDecimal newPrice = new BigDecimal(newSamplePrice);
                            compareSkuSamplePrice(newPrice, priceBySkuCode);

                        }


                        //compare 正装sku 的价格【和小样价格计算相关skum关联的正装】
                        compareSkuPrice(mergeMaster);
                    }
                }
            }

            //判断是否有新增 sku 表 new_order_sku_ntf
            getNewAddSkuList(operName, ownerIdAddSku);

            // SEND email
            StringBuffer emailBodyInfo = new StringBuffer("Dears,<br/>\n" +
                    "今天小样价格计算失败，请及时进行检查。 <br/><table border='5'><tr><th>品牌</th><th>产品编码</th><th>产品中文名称</th><th>产品英文名称</th><th>出现频次</th><th>小样类型</th><th>异常原因</th></tr>"
            );
            String emailBodyEnd = "</table>";

            //send email
            SkuSamplePriceCalErrorEntity skuSamplePriceCalError = new SkuSamplePriceCalErrorEntity();
            List<SkuSamplePriceCalErrorEntity> skuSamplePriceCalErrorList = skuSampleMapper.getSkuSamplePriceCalErrorLog(skuSamplePriceCalError);
            String times = "";
            String saleype = "";
            if (null != skuSamplePriceCalErrorList && !skuSamplePriceCalErrorList.isEmpty()) {
                for (SkuSamplePriceCalErrorEntity anEntity : skuSamplePriceCalErrorList) {
                    if (null != anEntity.getTimes()) {
                        times = anEntity.getTimes();
                    }
                    if (null != anEntity.getSaletype()) {
                        saleype = anEntity.getSaletype();
                    }
                    emailBodyInfo.append("<tr><td>").append(anEntity.getOwnerId()).append("</td>")
                            .append("<td>").append(anEntity.getGoodsCode()).append("</td>")
                            .append("<td>").append(anEntity.getGoodsName()).append("</td>")
                            .append("<td>").append(anEntity.getGoodsNameEn()).append("</td>")
                            .append("<td>").append(times).append("</td>")
                            .append("<td>").append(saleype).append("</td>")
                            .append("<td>").append(anEntity.getReason()).append("</td>></tr>");
                }
                emailBodyInfo.append(emailBodyEnd);
                Map<String, String> attachments = new HashMap<>();
                if (StringUtils.isNotEmpty(sendTo)) {
                    log.debug("send email subject{}, body={}, sendTo={}, ccTo={}", emaiSubject, emailBodyInfo.toString(), sendToAdd, ccToAdd);
                    boolean b = emailUtils.sendSkuEmail(sendTo, sendCc, emaiSubject, attachments, emailBodyInfo.toString());
                    if (!b) {
                        throw new GlobalException("发送邮件失败！");
                    }
                } else {
                    log.error("sendTo address is null, not send email");
                }
            }

        /*
        push data to DIP
         */
            //spu_master_data
            log.info("push data to dip spu_master_data");
            skuSampleMapper.pushToSpuMasterData();

            //skum_master_data
            log.info("push data to dip skum_master_data");
            skuSampleMapper.pushToSkumMasterData();


            //sku_data
            log.info("push data to dip sku_data");
            skuSampleMapper.pushToSkuData();

            //posm_value_data
            log.info("push data to dip posm_value_data");
            skuSampleMapper.pushToPosmValueData();


        } catch (Exception e) {
            //send email
            String[] sendTo = sendToAdd.split(",");
            String[] sendCc = ccToAdd.split(",");
            log.info("send email subject{}, body={}, sendTo={}, ccTo={}", emaiSubject, emailBodyError, sendToAdd, ccToAdd);
            emailBodyError.append("系统报错信息如下：<br/> " + e.getMessage());

            if (StringUtils.isNotEmpty(sendTo)) {
                boolean b = emailUtils.sendSkuEmail(sendTo, sendCc, emaiSubject, attachments, emailBodyError.toString());
                if (!b) {
                    throw new GlobalException("发送邮件失败！");
                }
            } else {
                log.error("sendTo address is null, not send email");
            }
            throw new RuntimeException(e);
        }

        return 0;
    }

    @Override
    public List<SkuSamplePriceCalErrorEntity> getSkuSamplePriceCalErrorLog(SkuSamplePriceCalErrorEntity entity) {
        List<SkuSamplePriceCalErrorEntity> retList = skuSampleMapper.getSkuSamplePriceCalErrorLog(entity);
        return retList;
    }

    @Override
    public List<SkuSampleUpdateLog> getSkuSampleUpdateLog(SkuSampleUpdateLog SkuSampleEntity) {
        List<SkuSampleUpdateLog> retList = skuSampleMapper.getSkuSampleUpdateLog(SkuSampleEntity);

        return retList;
    }

    /**
     * 新增小样的数据
     *
     */
    public void getNewAddSkuList(String operName, String ownerId) {

        List<SkuNewOrderSkuEntity> oneNewOrderSkuList = null;
        if (StringUtils.isNotEmpty(ownerId)) {
            String[] ownerIdArr = ownerId.split(",");
            oneNewOrderSkuList = skuSampleMapper.getNewOrderList(ownerIdArr);
        } else {
            oneNewOrderSkuList = skuSampleMapper.getNewOrderListTwo();
        }

        if (oneNewOrderSkuList.isEmpty()) {
            log.info("today={} no new add sku", LocalDate.now());
            return;
        }

        /*
        新增的小样写入日志
         */
        // 写入异常表
        for (SkuNewOrderSkuEntity newOrderSkuEntity : oneNewOrderSkuList) {
            SkuNewOrderSkuEntity skuNewOrderSkuEntity = new SkuNewOrderSkuEntity();
            SkuSampleEntity skuSampleEntity = new SkuSampleEntity();
            skuSampleEntity.setOwnerId(newOrderSkuEntity.getOwnerid());
            skuSampleEntity.setGoodsCode(newOrderSkuEntity.getProductcd());
            List<SkuSampleEntity> retList = skuSampleMapper.selectSkuSampleList(skuSampleEntity);
            if (null == retList || retList.isEmpty()) {
                log.info("new order not find info in sku_master,order={}", newOrderSkuEntity.toString());
                return;
            }
            SkuSampleEntity oldSkuMaster = retList.get(0);
            skuNewOrderSkuEntity.setOwnerid(oldSkuMaster.getOwnerId());
            skuNewOrderSkuEntity.setProductcd(oldSkuMaster.getGoodsCode());
            SkuNewOrderSkuEntity retSkuNewOrderSkuEntity = skuSampleMapper.getOneNewOrderSku(skuNewOrderSkuEntity);

            SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
            skuSamplePriceCalErrorEntity.setOwnerId(oldSkuMaster.getOwnerId());
            skuSamplePriceCalErrorEntity.setGoodsCode(oldSkuMaster.getGoodsCode());
            skuSamplePriceCalErrorEntity.setGoodsName(oldSkuMaster.getGoodsName());
            skuSamplePriceCalErrorEntity.setGoodsNameEn(oldSkuMaster.getGoodsNameEn());
            if (retSkuNewOrderSkuEntity != null) {
                skuSamplePriceCalErrorEntity.setTimes(retSkuNewOrderSkuEntity.getTimes());
            }
            skuSamplePriceCalErrorEntity.setSaletype(oldSkuMaster.getSaletype());
            skuSamplePriceCalErrorEntity.setReason("新增sku ownerId=" + oldSkuMaster.getOwnerId() + " skucode=" + oldSkuMaster.getGoodsCode());
            skuSamplePriceCalErrorEntity.setCreateBy(operName);
            skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());
            log.info("add new sku,info={}", skuSamplePriceCalErrorEntity.toString());
            skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);
        }

    }


    private void compareSkuSamplePrice(BigDecimal samplePrice, SkuSamplePriceEntity samplePriceEntity) {
        if (samplePrice.compareTo(samplePriceEntity.getSamplePrice()) == 0) {
            return;
        }

        //价格不相等  写日志到 sku_sample_price_update_log
        log.debug("old value={} and new value={} is diff", samplePriceEntity.getSamplePrice(), samplePrice);
        //追溯历史
        SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
        skuSampleUpdateLog.setOwnerId(samplePriceEntity.getOwnerId());
        skuSampleUpdateLog.setSkuCode(samplePriceEntity.getSkuCode());
        skuSampleUpdateLog.setSkuName(samplePriceEntity.getSkuName());
        skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_PRICE.getDesc()));
        skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SKU_SAMPLE_CAL_ERROR.getDesc()));
        skuSampleUpdateLog.setOldValue(String.valueOf(samplePriceEntity.getSalePrice()));
        skuSampleUpdateLog.setNewValue(String.valueOf(samplePrice));
        skuSampleUpdateLog.setUpdateBy("system");
        skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
        skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);

//        SkuSampleUpdateLog updateLog = new SkuSampleUpdateLog();
//        updateLog.setOwnerId(samplePriceEntity.getOwnerId());
//        updateLog.setSkuCode(samplePriceEntity.getSkuCode());
//        List<SkuSampleUpdateLog> retList = skuSampleMapper.getSkuSampleUpdateLog(updateLog);
//        if (null == retList || retList.isEmpty()) {
//            SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
//            skuSampleUpdateLog.setOwnerId(samplePriceEntity.getOwnerId());
//            skuSampleUpdateLog.setSkuCode(samplePriceEntity.getSkuCode());
//            skuSampleUpdateLog.setSkuName(samplePriceEntity.getSkuName());
//            skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_SAMPLE_CONTENT.getDesc()));
//            skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SKU_SAMPLE_CAL_ERROR.getDesc()));
//            skuSampleUpdateLog.setOldValue(String.valueOf(samplePriceEntity.getSalePrice()));
//            skuSampleUpdateLog.setNewValue(String.valueOf(samplePrice));
//            skuSampleUpdateLog.setUpdateBy("system");
//            skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
//            skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);
//        } else {
//            SkuSampleUpdateLog tmpLog = retList.get(0);
//            tmpLog.setOldValue(String.valueOf(samplePriceEntity.getSalePrice()));
//            tmpLog.setNewValue(String.valueOf(samplePrice));
//            tmpLog.setUpdateTime(DateUtils.getNowDate());
//            skuSampleMapper.updateSkuSampleUpdateLog(tmpLog);
//        }

        //update value
        SkuSamplePriceEntity skuSamplePriceEntity = new SkuSamplePriceEntity();
        skuSamplePriceEntity.setOwnerId(samplePriceEntity.getOwnerId());
        skuSamplePriceEntity.setSamplePrice(samplePrice);
        skuSamplePriceEntity.setUpdateBy("system");
        skuSamplePriceEntity.setUpdateTime(DateUtils.getNowDate());
        skuSampleMapper.updateSkuSamplePrice(skuSamplePriceEntity);
    }

    /*
    比较正装的价格
     */
    private void compareSkuPrice(SkuMergeMaster mergeMaster) {
        log.debug("enter compareSkuPrice mergeMaster={}", mergeMaster.toString());
        if (null != skuSampleSkumMap.get("SKU_SKUM_"+mergeMaster.getOwnerId()+"|"+mergeMaster.getSkumCode())){
            log.info("price hava compared.owner={},skumcode={}",mergeMaster.getOwnerId(), mergeMaster.getSkumCode());
        }
        else {
            skuSampleSkumMap.put("SKU_SKUM_"+mergeMaster.getOwnerId()+"|"+mergeMaster.getSkumCode(),"1");
            List<SkuPriceEntity> retList = skuSampleMapper.skuPriceCal4SkuSample(mergeMaster.getOwnerId(),mergeMaster.getSkumCode());
            for (SkuPriceEntity entity : retList){
                //log
                SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
                skuSampleUpdateLog.setOwnerId(entity.getOwnerId());
                skuSampleUpdateLog.setSkuCode(entity.getSkuCode());
                skuSampleUpdateLog.setSkuName(entity.getSkuName());
                skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_PRICE.getDesc()));
                skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SYS_EX.getDesc()));
                skuSampleUpdateLog.setOldValue(entity.getOldSkuPirce().setScale(2, RoundingMode.HALF_UP).toString());
                skuSampleUpdateLog.setNewValue(entity.getNewSkuPirce().setScale(2, RoundingMode.HALF_UP).toString());
                skuSampleUpdateLog.setUpdateBy("system");
                skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
                skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);

                SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
                skuSamplePriceCalErrorEntity.setOwnerId(entity.getOwnerId());
                skuSamplePriceCalErrorEntity.setGoodsCode(entity.getSkuCode());
                skuSamplePriceCalErrorEntity.setGoodsName(entity.getSkuName());
                skuSamplePriceCalErrorEntity.setGoodsNameEn(entity.getSkuNameEn());
                skuSamplePriceCalErrorEntity.setReason("正装 sku 价格变更,old price=" +entity.getOldSkuPirce().setScale(2, RoundingMode.HALF_UP) + " new price=" + entity.getNewSkuPirce().setScale(2, RoundingMode.HALF_UP));
                skuSamplePriceCalErrorEntity.setCreateBy("system");
                skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());
                skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);

            }
        }
    }

//    private void compareSkuPrice(SkuMergeMaster mergeMaster) {
//        log.debug("enter compareSkuPrice mergeMaster={}", mergeMaster.toString());
//        SkuMergeMasterSub skuMergeMasterSub = new SkuMergeMasterSub();
//        skuMergeMasterSub.setOwnerId(mergeMaster.getOwnerId());
//        skuMergeMasterSub.setSkumCode(mergeMaster.getSkumCode());
//        List<SkuMergeMasterSub> skuMergeMasterSubList = skuMergeMasterSubMapper.selectSkuMergeMasterSubList(skuMergeMasterSub);
//        if (skuMergeMasterSubList.isEmpty()) {
//            log.error("skum code=" + mergeMaster.getSkumCode() + " 没有sku");
//            return;
//        }
//
//        // get all 正装sku by sku_code
//        for (SkuMergeMasterSub masterSub : skuMergeMasterSubList) {
////            log.info("sku deal value={}", masterSub.toString());
//            if (StringUtils.isEmpty(masterSub.getOwnerId()) ||
//                    StringUtils.isEmpty(masterSub.getSkuCode())) {
//                log.error("please check! ownerid or sku code is null! skum={}", masterSub.toString());
//                continue;
//            }
//
//
//            BigDecimal newSalePrice = null;
//            SkuMaster newSkuMaster = null;
//            if (null != skuNewPriceMap.get("NEW_"+masterSub.getOwnerId()+"_"+masterSub.getSkuCode())){
//                newSkuMaster = skuNewPriceMap.get("NEW_"+masterSub.getOwnerId()+"_"+masterSub.getSkuCode());
//                newSalePrice = newSkuMaster.getSalePrice().setScale(2, RoundingMode.HALF_UP);
//            }
//            else {
//                newSkuMaster = skuMasterMapper.selectSkuMasterByGoodsCode(
//                        masterSub.getOwnerId(), masterSub.getSkuCode());
//                if (null == newSkuMaster) {
//                    log.error("no sku find. owner={} sku code={}", masterSub.getOwnerId(), masterSub.getSkuCode());
//                    continue;
//                }
//                skuNewPriceMap.put("NEW_"+masterSub.getOwnerId()+"_"+masterSub.getSkuCode(), newSkuMaster);
//                newSalePrice = newSkuMaster.getSalePrice().setScale(2, RoundingMode.HALF_UP);
//            }
//
//            BigDecimal OldSalePrice = null;
//            if (null != skuOldPriceMap.get("OLD_"+masterSub.getOwnerId()+"_"+masterSub.getSkuCode())){
//                OldSalePrice = skuOldPriceMap.get("OLD_"+masterSub.getOwnerId()+"_"+masterSub.getSkuCode());
//            }
//            else {
//                SkuMaster oldSkuMaster = skuMasterMapper.selectSkuMasterLogByGoodsCode(
//                        masterSub.getOwnerId(), masterSub.getSkuCode());
//                if (null == oldSkuMaster) {
//                    log.error("no sku find in log. owner={} sku code={}", masterSub.getOwnerId(), masterSub.getSkuCode());
//                    continue;
//                }
//                OldSalePrice = oldSkuMaster.getSalePrice().setScale(2, RoundingMode.HALF_UP);
//                skuOldPriceMap.put("OLD_"+masterSub.getOwnerId()+"_"+masterSub.getSkuCode(), OldSalePrice);
//
//            }
//
//            log.debug("newSalePrice={}, OldSalePrice={}", newSalePrice, OldSalePrice);
//            if (newSalePrice.compareTo(OldSalePrice) == 0) {
//                log.debug("two price equal.new price={}, old price={}", newSalePrice, OldSalePrice);
//                continue;
//            } else {
//                if (null != InsertLogFalgMap.get(newSkuMaster.getOwnerId()+"|"+newSkuMaster.getGoodsCode())){
//                    log.info("hava old log. ownerid={}, sku code={}",newSkuMaster.getOwnerId(), newSkuMaster.getGoodsCode());
//                }
//                else {
//                    InsertLogFalgMap.put(newSkuMaster.getOwnerId()+"|"+newSkuMaster.getGoodsCode(),"1");
//                    SkuNewOrderSkuEntity skuNewOrderSkuEntity = new SkuNewOrderSkuEntity();
//                    skuNewOrderSkuEntity.setOwnerid(newSkuMaster.getOwnerId());
//                    skuNewOrderSkuEntity.setProductcd(newSkuMaster.getGoodsCode());
//                    SkuNewOrderSkuEntity retSkuNewOrderSkuEntity = skuSampleMapper.getOneNewOrderSku(skuNewOrderSkuEntity);
//
//                    SkuSamplePriceCalErrorEntity skuSamplePriceCalErrorEntity = new SkuSamplePriceCalErrorEntity();
//                    skuSamplePriceCalErrorEntity.setOwnerId(newSkuMaster.getOwnerId());
//                    skuSamplePriceCalErrorEntity.setGoodsCode(newSkuMaster.getGoodsCode());
//                    skuSamplePriceCalErrorEntity.setGoodsName(newSkuMaster.getGoodsName());
//                    skuSamplePriceCalErrorEntity.setGoodsNameEn(newSkuMaster.getGoodsNameEn());
//                    if (retSkuNewOrderSkuEntity != null) {
//                        skuSamplePriceCalErrorEntity.setTimes(retSkuNewOrderSkuEntity.getTimes());
//                    }
//                    skuSamplePriceCalErrorEntity.setSaletype(newSkuMaster.getSaletype());
//                    skuSamplePriceCalErrorEntity.setReason("正装 sku 价格变更,old price=" + OldSalePrice.setScale(2, RoundingMode.HALF_UP) + " new price=" + newSalePrice.setScale(2, RoundingMode.HALF_UP));
//                    skuSamplePriceCalErrorEntity.setCreateBy("system");
//                    skuSamplePriceCalErrorEntity.setCreateTime(DateUtils.getNowDate());
//                    skuSampleMapper.insertSkuSamplePriceCalErrorLog(skuSamplePriceCalErrorEntity);
//
//                    //log
//                    SkuSampleUpdateLog skuSampleUpdateLog = new SkuSampleUpdateLog();
//                    skuSampleUpdateLog.setOwnerId(newSkuMaster.getOwnerId());
//                    skuSampleUpdateLog.setSkuCode(newSkuMaster.getGoodsCode());
//                    skuSampleUpdateLog.setSkuName(newSkuMaster.getGoodsName());
//                    skuSampleUpdateLog.setMtype(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_TYPE.SKU_PRICE.getDesc()));
//                    skuSampleUpdateLog.setMmodule(String.valueOf(SkuMasterConstants.SKU_SAMPLE_M_MODULE.SYS_EX.getDesc()));
//                    skuSampleUpdateLog.setOldValue(OldSalePrice.setScale(2, RoundingMode.HALF_UP).toString());
//                    skuSampleUpdateLog.setNewValue(newSalePrice.setScale(2, RoundingMode.HALF_UP).toString());
//                    skuSampleUpdateLog.setUpdateBy("system");
//                    skuSampleUpdateLog.setUpdateTime(DateUtils.getNowDate());
//                    skuSampleMapper.insertSkuSampleUpdateLog(skuSampleUpdateLog);
//                }
//            }
//        }
//    }
//

}
